#include "PrecompiledHeader.h"
#include "ConfigurationPanels.h"
#include "GS.h"
#include "App.h"
#include "Counters.h"
#include <wx/spinctrl.h>
/*
using namespace pxSizerFlags;

Panels::ValDanX_GSPanel::ValDanX_GSPanel( wxWindow* parent) :
	BaseApplicableConfigPanel( parent )
{
	const wxSizerFlags sliderFlags( wxSizerFlags().Border( wxLEFT | wxRIGHT, 8 ).Expand() );

	wxPanelWithHelpers* left	= new wxPanelWithHelpers( this, wxVERTICAL );

	left->SetMinWidth( 300 );

	wxStaticBoxSizer& groupSizer = *new wxStaticBoxSizer( wxVERTICAL, this, _("GS") );
	struct CheckTextMess
	{
		wxString label, tooltip;
	};
    const CheckTextMess check_text[NUM_OF_VALDANX_GS] =
	{ 
		{    
	        _("Enable 8 bit GS out [NOT RECOMMENDED]"),
			wxEmptyString
	    },
		{  
		    _("Enable 16 bit GS out [NOT RECOMMENDED]"),
			wxEmptyString
	    },
		{ 
			_("Enable 32 bit GS out [NOT RECOMMENDED]"),
			wxEmptyString
	    },
	    {    
	        _("Disable 64 bit GS write [WARNING!]"),
			wxEmptyString
	    },
		{    
	        _("Disable 64 bit GS read [RECOMMENDED]"),
			wxEmptyString
	    },
		{  
		    _("Enable 128 bit GS out [NOT RECOMMENDED]"),
			wxEmptyString
	    },
	    {    
	        _("Disable auto restart gif [RECOMMENDED]"),
			wxEmptyString
	    },
		{  
		    _("Disable auto restart gs [RECOMMENDED]"),
			wxEmptyString
	    },
		{ 
			 _("Reset MTGS hack [NOT RECOMMENDED]"),
			wxEmptyString
		},
		{    
	        _("Disable fifo 64 memory 1 sector [RECOMMENDED]"),
			wxEmptyString
	    },
		{  
		    _("Disable fifo 64 memory 2 sector [WARNING!]"),
			wxEmptyString
	    },
		{  
		    _("Enable auto gs clear complex 1 [BETA!]"),
			wxEmptyString
	    },
		{  
		    _("Enable auto gs clear complex 2 [BETA!]"),
			wxEmptyString
	    },
		{  
		    _("Enable auto gs clear complex 3 [BETA!]"),
			wxEmptyString
	    }
	};

/////////////////////////////////Button/////////////////////////////////
	for( int i=0; i<NUM_OF_VALDANX_GS; ++i )
	{
		groupSizer += (m_checkbox[i] = new pxCheckBox( this, check_text[i].label ));
		m_checkbox[i]->SetToolTip( check_text[i].tooltip );
	}

	s_table = new wxFlexGridSizer( 2 );
	s_table->AddGrowableCol( 0, 1 );
	s_table->AddGrowableCol( 1, 1 );

////////////////////////////////////////////////////////////////////////
wxButton* RestartGS    = new wxButton( left, wxID_ANY, _("Restart GS")           );
wxButton* RestartMTGS  = new wxButton( left, wxID_ANY, _("Restart MTGS")         );
wxButton* RestartGIF   = new wxButton( left, wxID_ANY, _("Restart GIF")          );
wxButton* ClearGIF     = new wxButton( left, wxID_ANY, _("Clear GIF")            );
wxButton* UVSR         = new wxButton( left, wxID_ANY, _("Update VSync Rate")    );
wxButton* GSRM         = new wxButton( left, wxID_ANY, _("GS Set Region Mode")   );
wxButton* complex1     = new wxButton( left, wxID_ANY, _("GS clear complex 1")   );
wxButton* complex2     = new wxButton( left, wxID_ANY, _("GS clear complex 2")   );
wxButton* complex3     = new wxButton( left, wxID_ANY, _("GS clear complex 3")   );
////////////////////////////////////////////////////////////////////////
*left	+= 7;
*left	+= RestartGS        | pxExpand;
*left	+= RestartMTGS      | pxExpand;
*left	+= 8;
*left	+= RestartGIF       | pxExpand;
*left	+= ClearGIF         | pxExpand;
*left	+= 8;
*left	+= UVSR             | pxExpand;
*left	+= GSRM             | pxExpand;
*left	+= 8;
*left	+= complex1         | pxExpand;
*left	+= complex2         | pxExpand;
*left	+= complex3         | pxExpand;
*s_table += left	        | pxExpand;
*s_table += groupSizer      | pxExpand;

*this	+= s_table      	| pxExpand;
wxPanelWithHelpers* r2	= new wxPanelWithHelpers( this, wxVERTICAL );
left->SetMinWidth( 200 );
	m_spin_FramesToSkipNTSC	= CreateNumericalTextCtrl( this, 7 );
	m_spin_FramesToSkipPAL	= CreateNumericalTextCtrl( this, 7 );
	m_spin_scanlinesNTSC	= CreateNumericalTextCtrl( this, 7 );
	m_spin_scanlinesPAL 	= CreateNumericalTextCtrl( this, 7 );

	wxFlexGridSizer& s_spins( *new wxFlexGridSizer( 4 ) );
	s_spins.AddGrowableCol( 0 );

	wxFlexGridSizer& s_spins2( *new wxFlexGridSizer( 4 ) );
	s_spins2.AddGrowableCol( 0 );


s_spins  += m_spin_FramesToSkipPAL			    | pxBorder(wxTOP, 2).Left();
s_spins  += 2;
s_spins	 += Label(_("Hz for PAL"))            	| StdExpand();
s_spins  += 10;

s_spins  += m_spin_FramesToSkipNTSC		    	| pxBorder(wxTOP, 2).Left();
s_spins  += 2;
s_spins	 += Label(_("Hz for NTSC"))           	| StdExpand();
s_spins  += 10;

s_spins2 += m_spin_scanlinesPAL  		    	| pxBorder(wxTOP, 2).Left();
s_spins2 += 2;
s_spins2 += Label(_("Scanlines for PAL (NOT TESTED!)"))    | StdExpand();
s_spins2 += 10;

s_spins2 += m_spin_scanlinesNTSC		    	| pxBorder(wxTOP, 2).Left();
s_spins2 += 2;
s_spins2 += Label(_("Scanlines for NTSC (NOT TESTED!)")) | StdExpand();
s_spins2 += 10;

wxButton* SpeedStable    = new wxButton( r2, wxID_ANY, _("Default Speed Stable")    );
wxButton* SpeedUnStable  = new wxButton( r2, wxID_ANY, _("Default Speed UnStable")  );
wxButton* SpeedWarning   = new wxButton( r2, wxID_ANY, _("Default Speed Warning")   );
*r2  += SpeedStable              | pxExpand;
*r2  += SpeedUnStable            | pxExpand;
*r2  += SpeedWarning             | pxExpand;

*this	+= new wxStaticLine( this )	| pxExpand.Border(wxLEFT | wxRIGHT, 20);
*this	+= s_spins;
*this	+= s_spins2;
*this	+= Text( pxE( ".Panel:ValDanX_GS:Heading",
		L"less - faster, more - smoother, 0 - auto" ));
*this	+= new wxStaticLine( this )	| pxExpand.Border(wxLEFT | wxRIGHT, 20);
*this   += 20;

*this+= r2			         	| pxExpand;

Connect( RestartGS->GetId(),   wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::GSreset)   );
Connect( RestartMTGS->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::MTGSReset) );
Connect( RestartGIF->GetId(),  wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::gsGIFreset));
Connect( ClearGIF->GetId(),    wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::gsGIFclear));
Connect( UVSR->GetId(),        wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::UpdateVSR) );
Connect( GSRM->GetId(),        wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::SetRegion) );

Connect( complex1->GetId(),    wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::complex_1) );
Connect( complex2->GetId(),    wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::complex_2) );
Connect( complex3->GetId(),    wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::complex_3) );

Connect( SpeedStable   -> GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::AppStatusEvent_DefaultSpeed  ) );
Connect( SpeedUnStable -> GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::AppStatusEvent_DefaultUnSpeed) );
Connect( SpeedWarning  -> GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ValDanX_GSPanel::AppStatusEvent_DefaultWarning) );
}

void Panels::ValDanX_GSPanel::Apply()
{
	Pcsx2Config::ValDanX_GSOptions& opts( g_Conf->EmuOptions.ValDanX_GS );
	try 
	{
		opts.FramesToSkipNTSC	= Fixed100::FromString( m_spin_FramesToSkipNTSC->GetValue() );
		opts.FramesToSkipPAL	= Fixed100::FromString( m_spin_FramesToSkipPAL->GetValue() );
		opts.scanlinesNTSC  	= Fixed100::FromString( m_spin_scanlinesNTSC->GetValue() );
		opts.scanlinesPAL   	= Fixed100::FromString( m_spin_scanlinesPAL->GetValue() );
	}
	catch( Exception::ParseError& )
	{
		throw Exception::CannotApplySettings( this,
			wxLt("Error while parsing either NTSC or PAL framerate settings.  Settings must be valid floating point numerics.")
		);
	}

	for (int i = 0; i < NUM_OF_VALDANX_GS; i++)
    {
        if (m_checkbox[i]->GetValue())
        {
            opts.bitset |= (1 << i);
        }
        else
        {
            opts.bitset &= ~(1 << i);
        }
	}
	UpdateVSyncRate();
}
void Panels::ValDanX_GSPanel::complex_1( wxCommandEvent& evt )
{
	Complex1();
}
void Panels::ValDanX_GSPanel::complex_2( wxCommandEvent& evt )
{
	Complex2();
}
void Panels::ValDanX_GSPanel::complex_3( wxCommandEvent& evt )
{
	Complex3();
}

void Panels::ValDanX_GSPanel::SetRegion( wxCommandEvent& evt )
{
	&gsSetRegionMode;
}
void Panels::ValDanX_GSPanel::UpdateVSR( wxCommandEvent& evt )
{
	VUpdateVSyncRate();
}
void Panels::ValDanX_GSPanel::GSreset( wxCommandEvent& evt )
{
	VgsReset();
}
void Panels::ValDanX_GSPanel::gsGIFreset( wxCommandEvent& evt )
{
	VgsGIFReset();
}
void Panels::ValDanX_GSPanel::gsGIFclear( wxCommandEvent& evt )
{
	GIFclear();
}
void Panels::ValDanX_GSPanel::MTGSReset( wxCommandEvent& evt )
{
	MTGSreset();
}
void Panels::ValDanX_GSPanel::AppStatusEvent_OnSettingsApplied()
{
	const Pcsx2Config::ValDanX_GSOptions& opts( g_Conf->EmuOptions.ValDanX_GS );

	m_spin_FramesToSkipPAL	->SetValue( opts.FramesToSkipPAL.ToString()   );
	m_spin_FramesToSkipNTSC	->SetValue( opts.FramesToSkipNTSC.ToString()  );

	m_spin_scanlinesPAL 	->SetValue( opts.scanlinesPAL.ToString()   );
	m_spin_scanlinesNTSC	->SetValue( opts.scanlinesNTSC.ToString()  );


	for( int i=0; i<NUM_OF_VALDANX_GS; ++i )
	{
		m_checkbox[i]->SetValue( !!(opts.bitset & (1 << i)) );
	}
}
void Panels::ValDanX_GSPanel::AppStatusEvent_DefaultSpeed( wxCommandEvent& evt )
{
	const Pcsx2Config::ValDanX_GSOptions& opts( g_Conf->EmuOptions.ValDanX_GS );
	ValDanX_GSPanel::m_checkbox[0]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[1]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[2]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[3]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[4]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[5]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[6]->SetValue( true );
	ValDanX_GSPanel::m_checkbox[7]->SetValue( true );
	ValDanX_GSPanel::m_checkbox[8]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[9]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[10]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[11]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[12]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[13]->SetValue( false );

	opts.FramesToSkipNTSC	== 14.985;
	opts.FramesToSkipPAL	== 25.00;
	m_spin_FramesToSkipPAL	->SetValue( opts.FramesToSkipPAL.ToString()  );
	m_spin_FramesToSkipNTSC	->SetValue( opts.FramesToSkipNTSC.ToString()  );
}
void Panels::ValDanX_GSPanel::AppStatusEvent_DefaultUnSpeed( wxCommandEvent& evt )
{
	const Pcsx2Config::ValDanX_GSOptions& opts( g_Conf->EmuOptions.ValDanX_GS );
	ValDanX_GSPanel::m_checkbox[0]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[1]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[2]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[3]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[4]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[5]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[6]->SetValue( true );
	ValDanX_GSPanel::m_checkbox[7]->SetValue( true );
	ValDanX_GSPanel::m_checkbox[8]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[9]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[10]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[11]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[12]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[13]->SetValue( false );

	opts.FramesToSkipNTSC	== 11.50;
	opts.FramesToSkipPAL	== 20.00;
	m_spin_FramesToSkipPAL	->SetValue( opts.FramesToSkipPAL.ToString()  );
	m_spin_FramesToSkipNTSC	->SetValue( opts.FramesToSkipNTSC.ToString()  );

}
void Panels::ValDanX_GSPanel::AppStatusEvent_DefaultWarning( wxCommandEvent& evt )
{
	const Pcsx2Config::ValDanX_GSOptions& opts( g_Conf->EmuOptions.ValDanX_GS );
	ValDanX_GSPanel::m_checkbox[0]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[1]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[2]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[3]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[4]->SetValue( true  );
	ValDanX_GSPanel::m_checkbox[5]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[6]->SetValue( true  );
	ValDanX_GSPanel::m_checkbox[7]->SetValue( true  );
	ValDanX_GSPanel::m_checkbox[8]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[9]->SetValue( true  );
	ValDanX_GSPanel::m_checkbox[10]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[11]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[12]->SetValue( false );
	ValDanX_GSPanel::m_checkbox[13]->SetValue( false );

	opts.FramesToSkipPAL	== 8.00;
	opts.FramesToSkipNTSC	== 5.00;
	m_spin_FramesToSkipPAL	->SetValue( opts.FramesToSkipPAL.ToString()  );
	m_spin_FramesToSkipNTSC	->SetValue( opts.FramesToSkipNTSC.ToString()  );
}
*/